package com.ruoyi.back.controller;

import java.util.List;

import com.ruoyi.back.domain.IndexTrain;
import com.ruoyi.back.service.IIndexTrainService;
import com.ruoyi.common.utils.uuid.SnowflakeIdUtils;
import io.swagger.annotations.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 首页培训风采Controller
 * 
 * @author luguanqing
 * @date 2021-04-06
 */
@Api(value="首页培训风采信息",description = "首页培训风采接口")
@RestController
@RequestMapping("/back/train")
public class IndexTrainController extends BaseController
{
    @Autowired
    private IIndexTrainService indexTrainService;

    /**
     * 查询首页培训风采列表
     */
    //@PreAuthorize("@ss.hasPermi('system:train:list')")
    @ApiOperation(value="首页培训风采列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "pageNum", value = "页数", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "pageSize", value = "每页记录数", required = true, dataType = "String"),
    })
    @GetMapping("/list")
    public TableDataInfo list(IndexTrain indexTrain)
    {
        startPage();
        List<IndexTrain> list = indexTrainService.selectIndexTrainList(indexTrain);
        return getDataTable(list);
    }

    /**
     * 导出首页培训风采列表
     */
    //@PreAuthorize("@ss.hasPermi('system:train:export')")
    @Log(title = "首页培训风采", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(IndexTrain indexTrain)
    {
        List<IndexTrain> list = indexTrainService.selectIndexTrainList(indexTrain);
        ExcelUtil<IndexTrain> util = new ExcelUtil<IndexTrain>(IndexTrain.class);
        return util.exportExcel(list, "train");
    }

    /**
     * 获取首页培训风采详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:train:query')")
    @ApiOperation(value="获取培训风采详情")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@ApiParam(name="id",value="培训风采id",required=true)@PathVariable("id") String id)
    {
        return AjaxResult.success(indexTrainService.selectIndexTrainById(id));
    }

    /**
     * 新增首页培训风采
     */
    //@PreAuthorize("@ss.hasPermi('system:train:add')")
    @ApiOperation(value="新增培训风采")
    @Log(title = "首页培训风采", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@ApiParam(name="培训风采对象",value="传入json格式",required=true)@RequestBody IndexTrain indexTrain)
    {
        indexTrain.setId(String.valueOf(new SnowflakeIdUtils(0, 0).nextId()));
        return toAjax(indexTrainService.insertIndexTrain(indexTrain));
    }

    /**
     * 修改首页培训风采
     */
    //@PreAuthorize("@ss.hasPermi('system:train:edit')")
    @ApiOperation(value="修改培训风采")
    @Log(title = "首页培训风采", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@ApiParam(name="培训风采对象",value="传入json格式",required=true)@RequestBody IndexTrain indexTrain)
    {
        return toAjax(indexTrainService.updateIndexTrain(indexTrain));
    }

    /**
     * 删除首页培训风采
     */
    //@PreAuthorize("@ss.hasPermi('system:train:remove')")
    @ApiOperation(value="删除培训风采")
    @Log(title = "首页培训风采", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@ApiParam(name="id",value="培训风采id",required=true)@PathVariable String[] ids)
    {
        return toAjax(indexTrainService.deleteIndexTrainByIds(ids));
    }
}
